unit Class_GkData;

interface
uses
  Classes,SysUtils;

type
  TGkData=class(TObject)
  private
    FListData:TStringList;
  public
    constructor Create;
    destructor Destroy; override;
  published
    property ListData:TStringList read FListData write FListData;
  public
    class procedure InitializeWithWsdl(AValue:string;var AList:TStringList);
    class procedure InitializeWithView(AValue:string;var AList:TStringList);
  end;

implementation

uses
  Class_KzUtils,NativeXml,Class_KzDebug;

{ TGkData }

constructor TGkData.Create;
begin
  FListData:=TStringList.Create;
end;

destructor TGkData.Destroy;
begin
  FreeAndNil(FListData);
  inherited;
end;


class procedure TGkData.InitializeWithView(AValue: string;
  var AList: TStringList);
begin
  //
end;

class procedure TGkData.InitializeWithWsdl(AValue: string;
  var AList: TStringList);
var
  I,M:Integer;
  StrmA:TStringStream;
  XMLA :TNativeXml;
  ROOT :TXmlNode;
  NODA :TXmlNode;
  NODB :TXmlNode;

  GkData:TGkData;
begin
  if AList=nil then Exit;
  TKzUtils.JustCleanList(AList);
  
  try
    StrmA:=TStringStream.Create(AValue);

    XMLA:=TNativeXml.Create(nil);
    XMLA.LoadFromStream(StrmA);
    XMLA.ExternalEncoding:=seUTF8;
    ROOT:=XMLA.Root;

    {KzDebug.FileFmt('rootname:%S',[ROOT.Name]);
    KzDebug.FileFmt('listnode:%D',[ROOT.NodeCount]);
    KzDebug.FileFmt('containercount:%D',[ROOT.ContainerCount]);}

    for I:=0 to ROOT.ContainerCount-1 do
    begin
      NODA:=ROOT.Containers[I];
      GkData:=TGkData.Create;
      
      //KzDebug.FileFmt('noda.name:%S',[NODA.NameUnicode]);
      for  M:=0 to NODA.ContainerCount-1 do
      begin
        NODB:=NODA.Containers[M];
        GkData.FListData.Add(Format('%S=%S',[NODB.Attributes[0].Value,NODB.Value]));
        {KzDebug.FileFmt('nodb.name:%S',[NODB.Name]);
        KzDebug.FileFmt('nodb.name:%S',[NODB.Value]);
        KzDebug.FileFmt('nodb.attr:%S',[NODB.Attributes[0].Value]);}
      end;

      AList.AddObject('',GkData);
    end;
  finally
    FreeAndNil(XMLA);
    FreeAndNil(StrmA);
  end;
end;



end.
